
#ifndef _BIT_DEFINE_H_
#define _BIT_DEFINE_H_

#include <stdint.h>


#define __BIT(x, bit) ((x) & (1UL << (bit)))
#define __BITS_MASK(high, low)	(((1ULL<<((high)+1))-1) & ~((1UL<<(low))-1))
#define __BIT_SHIFT(x, bit) (((x) >> (bit)) & 1)
#define __BITS(x, high, low) ((x) & (((1ULL<<((high)+1))-1) & ~((1UL<<(low))-1)))
#define __BITS_SHIFT(x, high, low) (((x) >> (low)) & ((1UL<<((high)-(low)+1))-1))

#define Bit(x)                      (1UL << (x))
#define Bits(start, end)             __BITS_MASK(end, start)
#define Bits_Get(val, start, end) (((val) & Bits((start),(end))) >> (start))
#define Bits_Test(val, start, end, tagval)	(Bits_Get(val, start, end) == (tagval))

#endif /*_BIT_DEFINE_H_*/


